﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Boggle;
using NUnit.Framework;

namespace BoggleTests
{
    [TestFixture]
    public class TraversalTests
    {
        public class TheCopyConstructor
        {
            [Test]
            public void VisitedCellsAreMaintained()
            {
                BoggleTraversal traversalA = new BoggleTraversal();
                BoggleCell aCell = new BoggleCell("a", 0, 0);
                BoggleCell bCell = new BoggleCell("b", 0, 1);
                traversalA.Visit(aCell);
                traversalA.Visit(bCell);

                //traversal b contains traversal a's cells
                BoggleTraversal traversalB = new BoggleTraversal(traversalA);
                Assert.That(traversalB.HasVisited(aCell));
                Assert.That(traversalB.HasVisited(bCell));
            }

            [Test]
            public void VisitedCellsIsDeepCopied()
            {
                BoggleTraversal traversalA = new BoggleTraversal();
                BoggleCell aCell = new BoggleCell("a", 0, 0);
                traversalA.Visit(aCell);

                BoggleTraversal traversalB = new BoggleTraversal(traversalA);
                BoggleCell bCell = new BoggleCell("b", 0, 1);
                traversalB.Visit(bCell);

                Assert.That(traversalB.HasVisited(bCell));
                Assert.That(traversalA.HasVisited(bCell) == false);

            }
        }
        public class TheToStringMethod
        {
            [Test]
            public void EachCellTraversedIsAppended()
            {
                BoggleTraversal traversal = new BoggleTraversal();
                BoggleCell aCell = new BoggleCell("a", 0, 0);
                BoggleCell bCell = new BoggleCell("b", 0, 1);
                BoggleCell cCell = new BoggleCell("c", 0, 2);
                traversal.Visit(aCell);
                traversal.Visit(bCell);
                traversal.Visit(cCell);
                Assert.That(traversal.ToString(), Is.EqualTo("abc"));
            }
        }

        public class TheHasVisitedMethod
        {
            [Test]
            public void EachVisitedCellReturnsTrue()
            {
                BoggleTraversal traversal = new BoggleTraversal();
                BoggleCell aCell = new BoggleCell("a", 0, 0);
                BoggleCell bCell = new BoggleCell("b", 0, 1);
                BoggleCell cCell = new BoggleCell("c", 0, 2);
                traversal.Visit(aCell);
                traversal.Visit(cCell);
                Assert.That(traversal.HasVisited(aCell), Is.EqualTo(true));
                Assert.That(traversal.HasVisited(cCell), Is.EqualTo(true));
            }

            [Test]
            public void EachUnvisitedCellReturnsFalse()
            {
                BoggleTraversal traversal = new BoggleTraversal();
                BoggleCell aCell = new BoggleCell("a", 0, 0);
                BoggleCell bCell = new BoggleCell("b", 0, 1);
                BoggleCell cCell = new BoggleCell("c", 0, 2);
                traversal.Visit(aCell);
                traversal.Visit(cCell);
                Assert.That(traversal.HasVisited(bCell), Is.EqualTo(false));
            }
        }

    }
}
